package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacher")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    /**
     *
     * @param page 当前页
     * @param limit 一页显示的数据
     * @return
     */
    @GetMapping("pageTeacher/{page}/{limit}")
    public R pageTeacher(@PathVariable  long page,@PathVariable long limit){

        Page<EduTeacher> eduTeacherPage = new Page<>(page,limit);
        Map<String,Object> map=teacherService.pageList(eduTeacherPage);
        return R.ok().data(map);

    }

    /**
     * 根据id获取讲师详细信息
     * @param teacherId
     * @return
     */
    @GetMapping("getMoreTeacher/{teacherId}")
    public R getMoreTeacher(@PathVariable String teacherId)
    {
        EduTeacher teacher = teacherService.getById(teacherId);
//        System.out.println(teacher);
        List<EduCourse> courses = courseService.selectByTeacherId(teacherId);
        return R.ok().data("teacherInfo",teacher).data("courseList",courses);

    }

}
